#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QRegExpValidator>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->lineEdit_name->setPlaceholderText("请输入用户名");
    ui->lineEdit_name->setClearButtonEnabled(true);

    ui->lineEdit_password->setPlaceholderText("请输入密码");
    ui->lineEdit_password->setEchoMode(QLineEdit::Password);
    ui->lineEdit_password->setClearButtonEnabled(true);
    ui->lineEdit_password->setMaxLength(15);

    ui->lineEdit_phone->setPlaceholderText("请输入电话号码");
//    ui->lineEdit_phone->setInputMask("000 0000 0000");
    // 正则表达式，以1开头后面跟10位数字
    ui->lineEdit_phone->setValidator(new QRegExpValidator(QRegExp("^1\\d{10}$")));
    ui->lineEdit_phone->setClearButtonEnabled(true);
    ui->lineEdit_phone->setMaxLength(11);

    ui->pushButton->setEnabled(false); // 禁用提交按钮

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    // 输出一下信息
    QString name = ui->label_name->text() + " " + ui->lineEdit_name->text();
    QString password = ui->label_password->text() + " " + ui->lineEdit_password->text();
    QString gender = ui->label_gender->text() + " ";
    if(ui->radioButton_male->isChecked())
        gender += ui->radioButton_male->text();
    if(ui->radioButton_female->isChecked())
        gender += ui->radioButton_female->text();
    QString phone = ui->label_phone->text() + " " + ui->lineEdit_phone->text();
    qDebug() << name;
    qDebug() << password;
    qDebug() << gender;
    qDebug() << phone;
}

void Widget::on_lineEdit_phone_textEdited(const QString &arg1)
{
    //验证
    QString str = arg1;
    int pos = 0;
    if(ui->lineEdit_phone->validator()->validate(str,pos) == QValidator::Acceptable)
        ui->pushButton->setEnabled(true);
    else
        ui->pushButton->setEnabled(false);
}
